 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>Local JSON Data Grid</title>
    <!-- grid.simple.min.css, grid.simple.min.js -->
    <link rel="stylesheet" href="css/bsgrid.all.min.css"/>
    <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="js/grid.zh-CN.min.js"></script>
    <script type="text/javascript" src="js/bsgrid.all.min.js"></script>
</head>
<?php
function juhecurl($url, $params = false, $ispost = 0) {
    $httpInfo = array();
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_USERAGENT , 'JuheData');
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , 60);
    curl_setopt($ch, CURLOPT_TIMEOUT , 60);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER , true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    if ($ispost) {
        curl_setopt($ch , CURLOPT_POST , true);
        curl_setopt($ch , CURLOPT_POSTFIELDS , $params);
        curl_setopt($ch , CURLOPT_URL , $url);
    } else {
        if ($params) {
            curl_setopt($ch , CURLOPT_URL , $url . '?' . $params);
        } else {
            curl_setopt($ch , CURLOPT_URL , $url);
        } 
    } 
    $response = curl_exec($ch);
    if ($response === false) {
        // echo "cURL Error: " . curl_error($ch);
        return false;
    } 
    $httpCode = curl_getinfo($ch , CURLINFO_HTTP_CODE);
    $httpInfo = array_merge($httpInfo , curl_getinfo($ch));
    curl_close($ch);
    return $response;
} 

/**
 * function Geturl($url){  
 * $ch=curl_init();  
 * curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);  
 * curl_setopt($ch,CURLOPT_URL,$url);  
 * curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);  
 * $resp=curl_exec($ch);  
 * curl_close($curl);  
 * return $resp;  
 * }  
 * #$mfg     = isset($_GET['mfg']) ? $_GET['mfg'] : $_POST['mfg'];  
 * $resp=Geturl("get_json.php");
 */
$di = mt_rand(1,1500);
$date = date('Y-m-d',strtotime("-$di day"));
$time =  strtotime($date); 
$appkey = "b967feebabb9ff6680dcdf6e767c7e5f"; 
// ************1.按更新时间查询笑话************
$url = "http://japi.juhe.cn/joke/content/list.from";
$params = array("sort" => "asc", // 类型，desc:指定时间之前发布的，asc:指定时间之后发布的
    "page" => "", // 当前页数,默认1
    "pagesize" => "", // 每次返回条数,默认1,最大20
    "time" => "$time", // 时间戳（10位），如：1418816972
    "key" => $appkey, // 您申请的key
    );
$paramstring = http_build_query($params);
$content = juhecurl($url, $paramstring);
$result = json_decode($content, true);
if ($result) {
    if ($result['error_code'] == '0') {
        # print_r($result);
    } else {
        echo $result['error_code'] . ":" . $result['reason'];
    } 
} else {
    echo "请求失败";
} 
$t_resp = $result['result'];
$resp = $t_resp['data'];
// 能获取json数据的接口
// json_decode()函数生成一个数组
// 用数组处理的方法就可以
// 就可以处理数据
/**
 * array(["a"]=>int(1) 
 * ["b"]=>int(2))
 */
// $resp=json_decode($resp,true);
 $resp = json_encode($resp);
#var_dump($resp);

?>
<body style="background-color: #fff;">
<table id="searchTable">
    <tr>
        <th w_index="employee_no" width="5%;">员工号</th>
        <th w_index="create_date" width="5%;">填写日期</th>
        <th w_index="spec_mfgno" w_align="left" width="15%;">作番</th>
        <th w_index="content" w_align="left" width="30%;">内容</th>
        <th w_index="updatetime" width="15%;">日期</th>
        <th w_index="spec_item" width="15%;">值</th>
        <th w_index="spec_contract" width="5%;">合约号</th>
       <!-- <th w_render="operate" width="10%;">Operate</th>-->
    </tr>
</table>
 <script type="text/javascript">
    var localData = <?php echo $resp;

?>
	/*[
    {
        "ID": 202,
        "CHAR": "1",
        "TEXT": "TEXT_TEXT_TEXT_TEXT_TEXT_TEXT_TEXT_TEXT_TEXT_TEXT_TEXT_1",
        "NUM": 11.2,
        "XH": 1
    },
    {
        "ID": 201,
        "CHAR": "111",
        "TEXT": "TEXT_TEXT_TEXT_TEXT_TEXT_TEXT_TEXT_TEXT_TEXT_TEXT_TEXT_2",
        "XH": 2
    },
    {
        "ID": 200,
        "CHAR": "200",
        "TEXT": "TEXT_TEXT_TEXT_TEXT_TEXT_TEXT_TEXT_TEXT_TEXT_TEXT_TEXT_3",
        "XH": 3
    },
    {
        "ID": 199,
        "CHAR": "199",
        "XH": 4
    },
    {
        "ID": 32,
        "CHAR": "34",
        "NUM": 12.1,
        "XH": 5
    }];*/
    var gridObj;
    $(function () {
        gridObj = $.fn.bsgrid.init('searchTable', {
            localData: localData,
            // autoLoad: false,
            pageSize: 20
        });
    });

    function operate(record, rowIndex, colIndex, options) {
        return '<a href="#" onclick="alert(\'ID=' + gridObj.getRecordIndexValue(record, 'ID') + '\');">Operate</a>';
    }
</script>
</body>
</html>
